import { ref, reactive, computed } from 'vue'
import { getExpertDetail } from '/@/api/expert/list'
import { getServiceTotal } from '/@/views/reserve/api'

export interface User {
  tenantId: string
  headPortrait: string
  expertInquiryName: string
  period: string | number
  qualifications: string
  remark: string
  consultFee: string
  [key: string]: any
}

export function useConsultant(userId: string, tenantId: string) {
  let user = ref<User | null>()

  let total = reactive({
    population: 0,
    duration: 0,
  })

  getExpertDetail(userId, tenantId).then((res) => {
    user.value = res.data.data
  })

  getServiceTotal({ userId }).then((res) => {
    let data = res.data.data
    total.duration = data.duration * 1.3
    total.population = data.population
  })

  const id = computed(() => {
    return user.value!.tenantId || ''
  })

  const category = computed(() => {
    let list: string[] = []
    let expertCategoryName = (user.value as any).expertCategoryName
    if (expertCategoryName && expertCategoryName.indexOf(',') > -1) {
      list = expertCategoryName.split(',')
    } else {
      list.push(expertCategoryName)
    }
    return list
  })

  return {
    user,
    total,
    category,
    id,
  }
}
